﻿package com.tudou.utils
{
    import flash.display.*;

    public class RectDisplayUtil extends Object
    {

        public function RectDisplayUtil()
        {
            return;
        }// end function

        public static function putChildByScale(param1:DisplayObject, param2:Number, param3:Number, param4:Number, param5:Number, param6:Boolean = false) : void
        {
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            if (isNaN(param2 + param3 + param4 + param5) || !param1)
            {
                return;
            }
            var _loc_7:* = param4 / param5;
            var _loc_8:* = param2 / param3;
            var _loc_9:* = _loc_7 > _loc_8;
            _loc_9 = param6 ? (!_loc_9) : (_loc_9);
            if (_loc_9)
            {
                _loc_11 = param5;
                _loc_10 = param5 * _loc_8;
                param1.scaleX = _loc_10 / param2;
                param1.scaleY = _loc_11 / param3;
                param1.x = (param4 - _loc_10) / 2;
                param1.y = 0;
            }
            else
            {
                _loc_10 = param4;
                _loc_11 = param4 / _loc_8;
                param1.scaleX = _loc_10 / param2;
                param1.scaleY = _loc_11 / param3;
                param1.x = 0;
                param1.y = (param5 - _loc_11) / 2;
            }
            return;
        }// end function

        public static function getMaskSprite(param1:Number = 100, param2:Number = 75, param3:uint = 0, param4:Number = 1) : Sprite
        {
            var _loc_5:* = getSprite(param1, param2, param3, param4);
            var _loc_6:* = getShape(param1, param2);
            _loc_5.addChild(_loc_6);
            _loc_5.mask = _loc_6;
            _loc_5.buttonMode = true;
            _loc_5.useHandCursor = true;
            return _loc_5;
        }// end function

        public static function drawRect(param1:Graphics, param2:Number = 100, param3:Number = 75, param4:uint = 0, param5:Number = 1) : void
        {
            param1.clear();
            param1.beginFill(param4, param5);
            param1.drawRect(0, 0, param2, param3);
            param1.endFill();
            return;
        }// end function

        public static function getSprite(param1:Number = 100, param2:Number = 75, param3:uint = 0, param4:Number = 1) : Sprite
        {
            var _loc_5:* = new Sprite();
            drawRect(_loc_5.graphics, param1, param2, param3, param4);
            return _loc_5;
        }// end function

        public static function getShape(param1:Number = 100, param2:Number = 75, param3:uint = 0, param4:Number = 1) : Shape
        {
            var _loc_5:* = new Shape();
            drawRect(_loc_5.graphics, param1, param2, param3, param4);
            return _loc_5;
        }// end function

        public static function putChild(param1:DisplayObject, param2:Number, param3:Number, param4:Boolean = false) : void
        {
            if (isNaN(param2) || isNaN(param3) || !param1)
            {
                return;
            }
            var _loc_5:* = param2 / param3;
            var _loc_6:* = param1.width / param1.height;
            var _loc_7:* = _loc_5 > _loc_6;
            _loc_7 = param4 ? (!_loc_7) : (_loc_7);
            if (_loc_7)
            {
                param1.height = param3;
                param1.width = param1.height * _loc_6;
                param1.x = (param2 - param1.width) / 2;
                param1.y = 0;
            }
            else
            {
                param1.width = param2;
                param1.height = param1.width / _loc_6;
                param1.x = 0;
                param1.y = (param3 - param1.height) / 2;
            }
            return;
        }// end function

    }
}
